/*
 * Copyright (c) 2008 Anshuman Manur <anshuman.manur@gmail.com>,
 * Lavanya Shastri <lavanya.shastri@gmail.com>
 * 
 * This file is part of Andronova.
 * 
 * Andronova is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 * 
 * Andronova is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with Andronova.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package com.googlecode.andronova;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SetPath extends Activity {

	private EditText eT;
	private String path;
	private SharedPreferences sP;
	
	public static final String SHARED_PREFERENCES_NAME = "SHARED";
	public static final String PREFERENCE_PATH = "PATH";
	
	@Override
	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.setpath_screen);
		setTitle("Set Path");
		
		sP = this.getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
		path = sP.getString(PREFERENCE_PATH, "");
		
		eT = (EditText) findViewById(R.id.setpath_et);
		eT.setText(path);
		
		Button bOK = (Button) findViewById(R.id.setpath_ok);
		bOK.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				String s = eT.getText().toString();
				Editor e = sP.edit();
				e.remove(PREFERENCE_PATH);
				e.putString(PREFERENCE_PATH, s);
				e.commit();
				setResult(RESULT_OK);
				finish();				
			}
		});
		
		Button bCancel = (Button) findViewById(R.id.setpath_cancel);
		bCancel.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				setResult(RESULT_CANCELED);
				finish();
			}
		});
	}	
}
